package com.personal.oa.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/13.
 * 更新数据时，链接sjdbcTemplate数据库
 * 整理主库数据时，链接pjdbcTemplate数据库
 */
@Repository
public class OADaoImpl implements OADao {

    @Autowired
    @Qualifier("primaryJdbcTemplate")
    protected JdbcTemplate pjdbcTemplate;

    @Autowired
    @Qualifier("secondaryJdbcTemplate")
    protected JdbcTemplate sjdbcTemplate;

    /**
     * 查询指定条数的object
     * @param startNum 开始行数
     * @param endNum 取多少行
     * @return
     */
    @Override
    public List<Map<String, Object>> findSpecifiedStrip(Integer startNum, Integer endNum) {
        String sql =
                "SELECT tb_info_oabook.*,oaobject_oabook.tb_typeid FROM tb_info_oabook " +
                "INNER JOIN oaobject_oabook " +
                "ON tb_info_oabook.obuuid = oaobject_oabook.obuuid " +
                "WHERE oaobject_oabook.oaid>? AND oaobject_oabook.oaid<=?";
        return pjdbcTemplate.queryForList(sql,new Object[]{startNum, endNum+1});//业务性+1，解决每一批数据最后一条数据无法录入(这样的解决办法在录入最后一条的时候总是少一)
    }

    /**
     * 获取oa_university_oai表中的oai
     * @param startNum
     * @param endNum
     * @return
     */
    @Override
    public List<String> oa_university_oai(Integer startNum, Integer endNum) {
        String sql ="SELECT obuuid FROM oa_university_oai WHERE oa_university_oai.oaid>? AND oa_university_oai.oaid<=? AND oa_university_oai.obuuid IS NOT NULL";
        return pjdbcTemplate.queryForList(sql,String.class,new Object[]{startNum, endNum+1});
    }

    /**
     * 获取详细信息
     * @param uuid
     * @return
     */
    @Override
    public List<Map<String,Object>> tb_info_doctor_master(String uuid) {
        String sql = "SELECT *,'3' AS tb_typeid FROM tb_info_doctor_master WHERE tb_info_doctor_master.obuuid=?";
        return pjdbcTemplate.queryForList(sql,new Object[]{uuid});
    }

}
